#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"

static TaskHandle_t hTask1 = NULL;
void myTask1(void *paraParam)
{
    UBaseType_t uxPriority = uxTaskPriorityGet(NULL);
    while (1)
    {
        uxPriority = uxTaskPriorityGet(NULL);
        printf("Task1 is running! p=%d\n", uxPriority);

        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

void myTask2(void *paraParam)
{
    UBaseType_t uxPriority = uxTaskPriorityGet(NULL); // 获取本任务的优先级
    while (1)
    {
        uxPriority = uxTaskPriorityGet(NULL);
        printf("Task2 is running! p=%d\n", uxPriority);
        vTaskPrioritySet(hTask1, 3); // 设置任务1的优先级
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

void app_main(void)
{
    // 任务2动态的更改任务1的优先级
    // 任务建立时，首先设置任务1的优先级为10
    // 当任务2运行后，将任务1的优先级改为3
    xTaskCreate(myTask1, "Task1", 2048, NULL, 10, &hTask1);
    xTaskCreate(myTask2, "Task2", 2048, NULL, 5, NULL);
}